package com.mall.common.constant;

import lombok.Getter;

/**
 * 消息发送状态枚举
 */
@Getter
public enum MessageStatusEnum {
    /**
     * 发送失败
     */
    FAILED(0, "发送失败"),

    /**
     * 发送成功
     */
    SUCCESS(1, "发送成功"),

    /**
     * 待发送
     */
    PENDING(2, "待发送");

    private final Integer code;
    private final String description;

    MessageStatusEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据code获取枚举
     *
     * @param code 状态码
     * @return 对应的枚举值
     */
    public static MessageStatusEnum fromCode(Integer code) {
        for (MessageStatusEnum status : MessageStatusEnum.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}